package com.javafactroy.kunlong.base.config.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import com.javafactroy.kunlong.base.context.GeneralBaseFactroy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class JdbcTemplateFactroy extends GeneralBaseFactroy<JdbcTemplate> {

    public JdbcTemplate findMysql() {
        for (JdbcTemplate jdbcTemplate : getList()) {
            DruidDataSource dataSource = (DruidDataSource) jdbcTemplate.getDataSource();
            if (dataSource.getDriverClassName().contains("mysql")) {
                return jdbcTemplate;
            }
        }
        return null;
    }

    public JdbcTemplate findOracle() {
        for (JdbcTemplate jdbcTemplate : getList()) {
            DruidDataSource dataSource = (DruidDataSource) jdbcTemplate.getDataSource();
            if (dataSource.getDriverClassName().contains("oracle")) {
                return jdbcTemplate;
            }
        }
        return null;
    }

    public JdbcTemplate findPostgres() {
        for (JdbcTemplate jdbcTemplate : getList()) {
            DruidDataSource dataSource = (DruidDataSource) jdbcTemplate.getDataSource();
            if (dataSource.getDriverClassName().contains("postgres")) {
                return jdbcTemplate;
            }
        }
        return null;
    }


}
